package com.tg.service.base.common;

import com.tg.service.base.createbean.A;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;

//@Component
public class MyBeanInstantiaitionAwareImpl implements InstantiationAwareBeanPostProcessor {

    @Override
    public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
////        Assert.isNull(beanClass,"beanClass不能为空");
//        if(ObjectUtils.nullSafeEquals(beanClass, SuperUser.class)){
//            SuperUser superUser = new SuperUser();
//            superUser.setName("一个船新的版本");
//            superUser.setAge(22);
//            return superUser;
//        }
        //默认什么都不做，返回null，继续下一步实例化
        return null;
    }

    @Override
    public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
        if (bean.getClass().equals(A.class)) {
            A target = (A) bean;
            target.setName("nameA");
            return false;
        }
        //默认返回true，什么也不做，继续下一步 初始化
        return true;
    }
}
